package com.winit.openapi.rma.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.fastjson.JSONObject;
import com.winit.oms.spi.common.OrderCalculateFeeService;
import com.winit.oms.spi.common.vo.SalesCalculateFeeResult;
import com.winit.oms.spi.inbound.InboundOrderFeeService;
import com.winit.oms.spi.rma.RMAOrderFeeService;
import com.winit.oms.spi.rma.command.EstimateOrderFeeCommand;
import com.winit.openapi.constants.ErrorCode;
import com.winit.openapi.controller.BaseController;
import com.winit.openapi.exception.ApiException;
import com.winit.openapi.model.RequestMsg;
import com.winit.openapi.model.ResponseMsg;
import com.winit.openapi.util.ValidateUtil;

/**
 * 退货费用相关接口
 * 
 * @version <pre>
 * Author	Version		Date		Changes
 * Winit 	1.0  		2016年3月7日 	Created
 *
 * </pre>
 * @since 1.
 */
@Controller
@RequestMapping(value = "/rma/fee")
public class RmaFeeController extends BaseController {

    @Resource
    private InboundOrderFeeService inboundOrderFeeService;
    @Resource
    private OrderCalculateFeeService orderCalculateFeeService;

    @Resource
    private RMAOrderFeeService rmaOrderFeeService;
    /**
     * 退货费用预估
     * 
     * @param requestMsg
     * @param responseMsg
     * @return
     */
    @RequestMapping(value = "/estimate")
    public String estimate(@ModelAttribute RequestMsg requestMsg, @ModelAttribute ResponseMsg responseMsg) {
        Object obj = requestMsg.getData();
        EstimateOrderFeeCommand command = new EstimateOrderFeeCommand();
        if (obj instanceof JSONObject) {
            JSONObject json = (JSONObject) obj;
            ValidateUtil.isNotNull(json, "returnGoodsOrderNo");
            command.setReturnGoodsOrderNo((json.getString("returnGoodsOrderNo")));
        } else {
            throw new ApiException(ErrorCode.FIELD_TYPE_ERROR, "data");
        }
        List<SalesCalculateFeeResult> result = rmaOrderFeeService.estimateOrderFee(command);
        responseMsg.setData(result);
        return SUCCESS;
    }
}
